/**
 * @file hal.h
 * @brief Header file for HAL (Hardware Abstraction Layer)
 *
 * @author Ricky Hariady (ricky.hariady@enter.web.id)
 *
 * @date 7/10/2013
 */

/**************************/
/*        Variable        */
/**************************/

int      *Rx_callback_ptr;       ///< pointer of Rx transmission handler to call by the interrupt handler

/**************************/
/*        Function        */
/**************************/

/**
 * @brief Configure serial device
 *
 * Set the serial device speed, etc
 *
 * @param baudrate baudrate used for transmission
 * @return Result
 */
int HAL_IO_Config(int baudrate);

/**
 * @brief Serial IO Interrupt Service Routine.
 *
 * check if there a data arrive, then Call transRx() function to collect it
 *
 * @return none
 */
void HAL_IO_ISR();

/**
 * @brief Receive 1 byte data.
 *
 * Receive 1 byte data from from serial IO
 *
 * @return the data byte received
 */
uint8_t HAL_IO_RxByte();

/**
 * @brief Transmit 1 byte data.
 *
 * Transmit 1 byte data to serial IO
 *
 * @param data data byte to transmit
 * @return Result
 */
int HAL_IO_TxByte(uint8_t data);

/**
 * @brief Read 1 byte data.
 *
 * Read 1 byte data from non-volatile memory (EEPROM/Flash)
 *
 * @param address virtual address of memory want to read
 * @return data readed
 */
uint8_t HAL_Mem_ReadByte(int address);

/**
 * @brief Write 1 byte data.
 *
 * Write 1 byte data to non-volatile memory (EEPROM/flash)
 *
 * @param address virtual address of memory want to write
 * @param data data want to write
 * @return Result
 */
uint8_t HAL_Mem_WriteByte(int address, uint8_t data);

/**
 * @brief Read block of data.
 *
 * Read block of data from non-volatile memory (EEPROM/Flash)
 *
 * @param address virtual address of beginning of memory want to read
 * @return data readed
 */
int HAL_Mem_ReadBlock(int address, int size, uint8_t * data);

/**
 * @brief Write block of data.
 *
 * write block of data to non-volatile memory (EEPROM/Flash)
 *
 * @param address virtual address of beginning of memory want to read
 * @return data readed
 */
int HAL_Mem_WriteBlock(int address, int size, uint8_t * data);

/**
 * @brief Check the integrity
 *
 * Check integrity of non-volatile memory (EEPROM/flash)
 *
 * @param address virtual address of memory want to check
 * @return Result
 */
int HAL_Mem_Check();

/**
 * @brief Initialize memory
 *
 * Initialize the  non-volatile memory (EEPROM/flash).
 * Call once when OS Finalize.
 *
 * @return virtual size of the memory available
 */
int HAL_Mem_Initialize();

int HAL_Mem_DeInitialize();
